package com.zzyk.main.configuration.shiro.filter;


import com.alibaba.fastjson.JSON;
import com.zzyk.main.model.vo.Message;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.web.servlet.AdviceFilter;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;

public class LogoutFilter extends AdviceFilter {
    @Override
    protected boolean preHandle(ServletRequest request, ServletResponse response) throws Exception {
        HttpServletResponse resp = (HttpServletResponse) response;
        resp.setContentType("application/json;charset=utf-8");
        resp.setCharacterEncoding("UTF-8");
        resp.getWriter().write(JSON.toJSONString(Message.success("您已安全退出")));
        Subject subject = SecurityUtils.getSubject();
        subject.logout();
        return false;
    }
}
